var backuserlist = {
		
		curPage : 1,
		pageSize : 20,
		
		initPage : function(){
			backuserlist.initBtn();
			backuserlist.getDatalist(0);
			$("#addBtn").html(language.addUser[mainIndex.languageType]);
			$("#userlist").html(language.userlist[mainIndex.languageType]);
			$("#qryBtn").html(language.query[mainIndex.languageType]);
			$("#serialNumber").html(language.serialNumber[mainIndex.languageType]);
			$("#userName").html(language.userName[mainIndex.languageType]);
			$("#itemQuantity").html(language.itemQuantity[mainIndex.languageType]);
			$("#remark").html(language.remark[mainIndex.languageType]);
			$("#createTime").html(language.createTime[mainIndex.languageType]);
			$("#operation").html(language.operation[mainIndex.languageType]);
			$("#nickName").attr('placeholder',language.userName[mainIndex.languageType]+"...");
		},
		
		initBtn : function(){
			$("#addBtn").click(function(){
				backuserlist.addUser();
			});
			$("#qryBtn").click(function(){
				backuserlist.getDatalist(0);
			});
		},
		
		getDatalist : function(pageIndex){
			$('#backuserlist').html('<tr><td  colspan="10"  style="text-align:center;">'+language.querying[mainIndex.languageType]+'...</td></tr>');
			$('#backuserlistpage').html("");
			pageIndex=(pageIndex==null)? 0:pageIndex;
			var params = {};
			params['curPage'] = pageIndex + 1;
			params['pageSize'] = backuserlist.pageSize;
			params['userType'] = "1";
			params['account'] = $("#nickName").val();
			usermanager.getUserList(params, backuserlist.getbackuserlist_Succ, backuserlist.getbackuserlist_error);
			backuserlist.curPage = pageIndex + 1;
		},
		
		getbackuserlist_Succ : function(data){
			if(data && data.retCode == 0){
				var _html = '';
				if(data.data && data.data.length > 0){
					for(var key in data.data){
						var item = data.data[key];
						if(item.userType=='1'){
							continue;
						}
						if(item.versionSize==null){
							item.versionSize=0;
						}
						_html += '<tr><td class="tal"> '+((parseInt(backuserlist.curPage)-1)*backuserlist.pageSize + (parseInt(key)+1))+'</td>';
						_html += '<td class="tal">'+item.account+'</td>';
						_html += '<td class="tal">'+item.versionSize+'</td>';
						_html += '<td class="tal">'+item.remark+'</td>';
						_html += '<td class="tal">'+item.createTime+'</td>';
						if(item.account=='admin'){
							_html += '<td></td></tr>';
						}else{
							_html += '<td><button class="btn btn-warning radius" onclick=\"javascript:backuserlist.editUser('+item.userId+');\">'+language.edit[mainIndex.languageType]+'</button>';
							_html += ' <button class="btn btn-danger radius" onclick="backuserlist.singleDel('+item.userId+')">'+language.del[mainIndex.languageType]+'</button></td></tr>';
						}
					}
					$('#backuserlist').html(_html);
					if(data.page){
						util.paginationPage($('#backuserlistpage'), data.page.totalPage, parseInt(data.page.curPage-1), backuserlist.getDatalist,true);
					}
				}else{
					$('#backuserlist').html('<tr  align="center"><td id="noData" colspan=10>'+language.noData[mainIndex.languageType]+'</td></tr>');
					$('#backuserlistpage').html("");
				}
			}else{
				$.dialog( {
					title : '错误',
					icon : 'error',
					content : language.getError[mainIndex.languageType],
					time : 3
				});
			}
		},
		
		getbackuserlist_error:function(data){
			window.location.reload();
		},
		
		
		addUser : function(){
			layer.open({
				type:2,
				content:util.webpath+'user/addUser.html',
				area: ['500px', '300px'],
			});
//			util.loadContent(util.webpath+'user/addUser.html','contentDiv',{},function(){
//				adduser.initPage();
//			});
		},

		editUser : function(id){
			util.loadContent(util.webpath+'user/addUser.html','contentDiv',{},function(){
				adduser.id=id;
				adduser.initPage();
			});
		},
		
		singleDel:function(userId){
			layer.confirm(language.confirmdelete[mainIndex.languageType], {
				  btn: [language.confirm[mainIndex.languageType],language.cancel[mainIndex.languageType]] //按钮
				}, function(){
					usermanager.delUser({"userId":userId},function(){
						layer.msg(language.operatorSuccess[mainIndex.languageType], {icon: 1});
						backuserlist.getDatalist(0);
					});
				});
		},
		
		
};
backuserlist.initPage();
